# -*- coding: utf-8 -*-

################################################################################
## Form generated from reading UI file '动态设置文本的字体和颜色.ui'
##
## Created by: Qt User Interface Compiler version 5.15.2
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################

from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *
from PySide2 import QtCore, QtGui, QtWidgets
from PySide2.QtWidgets import QFontDialog, QColorDialog
import sys


class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        if not MainWindow.objectName():
            MainWindow.setObjectName(u"MainWindow")
        MainWindow.resize(800, 600)
        self.centralwidget = QWidget(MainWindow)
        self.centralwidget.setObjectName(u"centralwidget")
        self.widget = QWidget(self.centralwidget)
        self.widget.setObjectName(u"widget")
        self.widget.setGeometry(QRect(200, 150, 361, 321))
        self.verticalLayout = QVBoxLayout(self.widget)
        self.verticalLayout.setObjectName(u"verticalLayout")
        self.verticalLayout.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout = QHBoxLayout()
        self.horizontalLayout.setObjectName(u"horizontalLayout")
        self.pushButton = QPushButton(self.widget)
        self.pushButton.setObjectName(u"pushButton")

        self.horizontalLayout.addWidget(self.pushButton)

        self.horizontalSpacer = QSpacerItem(140, 20, QSizePolicy.Fixed, QSizePolicy.Minimum)

        self.horizontalLayout.addItem(self.horizontalSpacer)

        self.pushButton_2 = QPushButton(self.widget)
        self.pushButton_2.setObjectName(u"pushButton_2")

        self.horizontalLayout.addWidget(self.pushButton_2)


        self.verticalLayout.addLayout(self.horizontalLayout)

        self.textEdit = QTextEdit(self.widget)
        self.textEdit.setObjectName(u"textEdit")

        self.verticalLayout.addWidget(self.textEdit)

        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QMenuBar(MainWindow)
        self.menubar.setObjectName(u"menubar")
        self.menubar.setGeometry(QRect(0, 0, 800, 26))
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QStatusBar(MainWindow)
        self.statusbar.setObjectName(u"statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)

        # 对“设置字体”和“设置颜色”按钮进行信号和槽的设定
        self.pushButton.clicked.connect(self.setFont)
        self.pushButton_2.clicked.connect(self.setColor)

        QMetaObject.connectSlotsByName(MainWindow)
    # setupUi

    def retranslateUi(self, MainWindow):
        MainWindow.setWindowTitle(QCoreApplication.translate("MainWindow", u"\u52a8\u6001\u8bbe\u7f6e\u6587\u672c\u7684\u5b57\u4f53\u548c\u989c\u8272", None))
        self.pushButton.setText(QCoreApplication.translate("MainWindow", u"\u8bbe\u7f6e\u5b57\u4f53", None))
        self.pushButton_2.setText(QCoreApplication.translate("MainWindow", u"\u8bbe\u7f6e\u989c\u8272", None))
    # retranslateUi
    # 分别定义 “设置字体”和“设置颜色”的槽函数
    def setFont(self):
        ok, font = QFontDialog.getFont()          # 字体对话框
        if ok:                                    # 如果选择了字体
            self.textEdit.setFont(font)           # 将选择的字体作为标签的字体

    def setColor(self):
        color = QColorDialog.getColor()        # 创建颜色对话框
        if color.isValid():                          # 判断颜色是否可用
            self.textEdit.setTextColor(color)      # 将选择的颜色作为标签的字体


if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())

